package com.smyh.model.device;

import android.widget.EditText;

import com.smyh.bean.DeviceMockInfo;
import com.smyh.bean.DigitDeviceInfo;
import com.smyh.cache.DeviceDigitalInfoCache;
import com.smyh.cache.DeviceMockInfoCache;
import com.smyh.cache.UIM.MainCahce;

/**
 * Created by Administrator on 2016/8/1.
 */
public class DeviceStateInfoModel {
    /**
     * 模拟量组件
     */
    private static EditText runElec01,batVolt02,faultElec03,lineTem04,earthElecFiled05,fetchSelfVolt06,
            stateInfo07,faultInfo8;
    /**
     * 遥信量组件
     */
    private static EditText shortCut09, earthFault11, batError;
    private static EditText shortCutTimer10, earthFaultTime,batErrorTime;

    public static void initDeviceStateComp(EditText runElec01,EditText batVolt02,EditText faultElec03,EditText lineTem04,EditText earthElecFiled05,
                                      EditText fetchSelfVolt06,EditText stateInfo07,EditText faultInfo8,EditText shortCut09, EditText earthFault11,
                                      EditText batError,EditText shortCutTimer10, EditText earthFaultTime,EditText batErrorTime){
        DeviceStateInfoModel.runElec01 = runElec01;
        DeviceStateInfoModel.batVolt02 = batVolt02;
        DeviceStateInfoModel.faultElec03 = faultElec03;
        DeviceStateInfoModel.lineTem04 = lineTem04;
        DeviceStateInfoModel.earthElecFiled05 = earthElecFiled05;
        DeviceStateInfoModel.fetchSelfVolt06 = fetchSelfVolt06;
        DeviceStateInfoModel.stateInfo07 = stateInfo07;
        DeviceStateInfoModel.faultInfo8 = faultInfo8;

        DeviceStateInfoModel.shortCut09 = shortCut09;
        DeviceStateInfoModel.earthFault11 = earthFault11;
        DeviceStateInfoModel.batError = batError;

        DeviceStateInfoModel.shortCutTimer10 = shortCutTimer10;
        DeviceStateInfoModel.earthFaultTime = earthFaultTime;
        DeviceStateInfoModel.batErrorTime = batErrorTime;
    }

    /**
     * 刷新选择设备的设备遥测、遥信数据
     */
    public static void freshDeviceStateData(){

        DeviceMockInfo deviceMockInfo = DeviceMockInfoCache.getDeviceMockMap().get(MainCahce.chooseDeviceAddr);
        if(deviceMockInfo != null){
            DeviceStateInfoModel.runElec01.setText(""+deviceMockInfo.getLoadElec());
            DeviceStateInfoModel.batVolt02.setText(""+deviceMockInfo.getBatteryElecVolt());
            DeviceStateInfoModel.faultElec03.setText(""+deviceMockInfo.getFaultElec());
            DeviceStateInfoModel.lineTem04.setText(""+deviceMockInfo.getCableTemper());
            DeviceStateInfoModel.earthElecFiled05.setText(""+deviceMockInfo.getGroupField());
            DeviceStateInfoModel.fetchSelfVolt06.setText(""+deviceMockInfo.getCapacitanceElecVolt());
            DeviceStateInfoModel.stateInfo07.setText(""+deviceMockInfo.getStateInfo());
            DeviceStateInfoModel.faultInfo8.setText(""+deviceMockInfo.getFaultInfo());

        }else {

            DeviceStateInfoModel.runElec01.setText(" ");
            DeviceStateInfoModel.batVolt02.setText(" ");
            DeviceStateInfoModel.faultElec03.setText(" ");
            DeviceStateInfoModel.lineTem04.setText(" ");
            DeviceStateInfoModel.earthElecFiled05.setText(" ");
            DeviceStateInfoModel.fetchSelfVolt06.setText(" ");
            DeviceStateInfoModel.stateInfo07.setText(" ");
            DeviceStateInfoModel.faultInfo8.setText(" ");
        }
        DigitDeviceInfo digitDeviceInfo = DeviceDigitalInfoCache.getDeviceDigitMap().get(MainCahce.chooseDeviceAddr);
        if(digitDeviceInfo != null){
            DeviceStateInfoModel.shortCut09.setText(""+digitDeviceInfo.getShortFault0());
            DeviceStateInfoModel.earthFault11.setText(""+digitDeviceInfo.getEarthFault0());
            DeviceStateInfoModel.batError.setText(""+digitDeviceInfo.getBatteryFault0());

        }else {

            DeviceStateInfoModel.shortCut09.setText("");
            DeviceStateInfoModel.earthFault11.setText("");
            DeviceStateInfoModel.batError.setText("");
        }
    }
}
